package com.pirestupppai.rxbus;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.pirestupppai.R;
import com.pirestupppai.utils.NetworkUtil;
import com.pirestupppai.utils.Utils;


/**
 * 监听网络状态
 *
 * @author: xiaoluo
 * @date: 2017-01-22 16:17
 */
public class NetworkStateReceiver extends BroadcastReceiver {
    private int networkType;

    public NetworkStateReceiver(int networkType) {
        this.networkType = networkType;
    }
    @Override
    public void onReceive(Context context, Intent intent) {
        int type = NetworkUtil.getNetworkType();
        if (networkType != type) {
            if (!NetworkUtil.isNetworkConnected(context)) {
                Utils.showToast(context.getResources().getString(R.string.error_no_network));
            }
        }
    }
}
